﻿using System;
using UnityEngine;
using UnityEngine.UI;

namespace JQMergeFramework
{
    public class UIPreviewLvTips:MonoBehaviour
    {
        public Text lvTips;
        private CityUnit mBindCity = null;
        
        private RectTransform rect;

        private Vector2 offet = new Vector3(0, 70);
        public void BindCity(CityUnit city)
        {
            this.transform.SetParent(UICityLvTips.I.transform);
            
            rect = this.transform.parent.GetComponent<RectTransform>();
            mBindCity = city;
       
            lvTips.text = string.Format("Lv.{0}", mBindCity.Level+1);

            RefreshCityState();
        }

        //刷新状态
        public void RefreshCityState()
        {
            // if (mBindCity!=null)
            // {
            //     switchChild.index = mBindCity.mTrackUnit.showIndex == 0 ? 0:1;
            // }
        }

        public void Clear()
        {
            mBindCity = null;
        }

        private void LateUpdate()
        {
            if (mBindCity!=null)
            {
                Vector3 pos = PositionConvert.WorldPointToScreenPoint(mBindCity.transform.position);
                Vector2 screenPoint =PositionConvert.ScreenPointToUIPoint(rect, pos);
                this.transform.localPosition =   screenPoint - offet;
            }
        }
    }
}